import collections
class Solution(object):
    def wordSubsets(self, words1, words2):
        d = collections.Counter()
        for word in words2:
            t = collections.Counter(word)
            for key in t:
                d[key] = max(d[key], t[key])
        out = []
        for word in words1:
            t = collections.Counter(word)
            if not d - t:
                out.append(word)
        return out




data = Solution()
words1 = ["amazon", "apple", "facebook", "google", "leetcode"]
words2 = ["ec", "oc", "ceo"]
print(data.wordSubsets(words1, words2))
